#include <bits/stdc++.h>
using namespace std;

int T;
int n, m;
double L , V;
struct node
{
    double d, v, a;
}b[1000001];

int w[1000001];
int answ[1000001];
int number;
int pd[1000001];

void intprint()
{
    cin >> n >> m >> L >> V;
    for(int i = 1; i <= n; i++)
        cin >> b[i].d >> b[i].v >> b[i].a;
    for(int i = 1; i <= m; i++)
        cin >> w[i];
}

void yunsu(int now)
{
    if( b[now].v <= V) return;
    else
    {
        for(int i = 1; i <= n; i++)
        {
            if( b[now].d < w[i])
            {
                answ[w[i]]++;
            }
        }

        for(int i = 1; i <= n; i++)
        {
            if( b[now].d < w[i])
            {
                number += 1;
                return;
            }
        }
    }
}

void jiasu(int now)
{
    if( b[now].v > V)
    {
        for(int i = 1; i <= n; i++)
        {
            if( b[now].d < w[i])
            {
                answ[w[i]]++;
            }
        }

        for(int i = 1; i <= n; i++)
        {
            if( b[now].d < w[i])
            {
                number += 1;
                return;
            }
        }
    }
    else
    {
        double s = (V*V - b[now].v * b[now].v ) / (2 * b[now].a) + b[now].d;
        if(s < w[m])
        {
            for(int i = 1; i <= n; i++)
            {
                if( s < w[i])
                {
                    answ[w[i]]++;
                }
            }

            for(int i = 1; i <= n; i++)
            {
                if( s < w[i])
                {
                    number += 1;
                    return;
                }
            }
        }
    }
}

void jiansu(int now)
{
    if( b[now].v < V) return;
    else
    {
        double s = (V*V - b[now].v * b[now].v ) / (2 * b[now].a) + b[now].d;
        if(s < w[m])
        {
            for(int i = 1; i <= n; i++)
            {
                if( s > w[i] && w[i] >= b[now].d)
                {
                    answ[w[i]]++;
                }
            }
            for(int i = 1; i <= n; i++)
            {
                if( s > w[i] && w[i] > b[now].d)
                {
                    number += 1;
                    return;
                }

            }
        }
    }
}

int main()
{
    memset(pd,1,sizeof(pd));
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin >> T;
    for(int zho = 1; zho <= T; zho++)
    {

        intprint();

        for(int i = 1; i <=n; i++)
        {
            if( b[i].a == 0) yunsu(i);
            else if( b[i].a < 0) jiansu(i);
            else jiasu(i);
        }

        int num = 0;
        for(int i = 1; i <= n; i++)
        {
            if( pd[answ[w[i]]] != 0 && answ[w[i]] != 0)
            {
                pd[answ[w[i]]] = 0;
                num++;
            }
        }
        cout << number << " " << m - num << endl;
        number = 0;
        memset(b,0,sizeof(b));
        memset(w,0,sizeof(w));
        memset(answ,0,sizeof(answ));
    }
    return 0;
}
